<?php
session_start();

/**
 * Script used to fetch a particular page from the database
 */

/*
 *  Get information about a certain page
 *  selected by $_POST['id'].
 *
 */

// Return json encoded data
header ('Content-type: application/json');
require_once '../core/db.php';
if(isset($_SESSION['user'])) {
    $sql = "SELECT pageId, pageName, parent, private FROM sitePages WHERE userId=? AND pageId=?";
    $sth = $db->prepare ($sql);
    $sth->execute(array ($_SESSION['user'], $_POST['id']));
    $res = $sth->fetch(PDO::FETCH_ASSOC);
    if ($res) {
        echo json_encode  ($res);
    }
    else {
        echo json_encode  (array ('message'=>'Du kan ikke redigere side uten � eie den.'));
    }
}
else {
    echo json_encode (array ('message'=>'Du kan ikke redigere side uten � v�re logget inn.'));
}
?>